package com.shenzhen.horselive.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.shenzhen.horselive.R;
import com.shenzhen.horselive.databinding.DialogUpdateApkBinding;

public class UpdateDialog  extends Dialog {
    private  OnUpdateClick  onUpdateClick;
    public UpdateDialog(@NonNull Context context) {
        super(context, R.style.CommonDialog);
        intiViews();
    }

    public void setOnUpdateClick(OnUpdateClick onUpdateClick) {
        this.onUpdateClick = onUpdateClick;
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width= ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height= ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = Gravity.CENTER;
        getWindow().setAttributes(layoutParams);
    }

    DialogUpdateApkBinding  binding;
    private void intiViews() {
        binding = DialogUpdateApkBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.btCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        binding.btGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onUpdateClick!=null)
                {
                    onUpdateClick.onClick();
                }
            }
        });
    }

    public void   setFouce(boolean  fouce)
    {
        //强制更新
        if (fouce)
        {
            binding.btCancel.setVisibility(View.GONE);
            setCancelable(false);
            setCanceledOnTouchOutside(false);
        }
    }

    public  void   setData(String  versionName,String  notice)
    {
        binding.tvVersionName.setText(versionName);
        binding.tvNotice.setText(notice);
    }



    public  interface OnUpdateClick{
        void  onClick();
    }



}
